package cqu.java.multiTomulti;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyService {
	private Lock lock = new ReentrantLock();
	private Condition condition = lock.newCondition();
	private boolean hasValue = false;
	
	public void set() {
		try {
			lock.lock();
			while(hasValue==true){
				System.out.println("有可 XX 能连续");
				condition.await();
			}
			System.out.println("打印 V V");
			hasValue = true;
			//condition.signal();
			condition.signalAll();
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
		}
	}
	
	public void get() {
		try {
			lock.lock();
			while(hasValue == false){
				System.out.println("有可  * * 能连续");
				condition.await();
			}
			System.out.println("打印 ###");
			hasValue = false;
			//condition.signal();
			condition.signalAll();
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
		}
	}

}
